package com.nectech.entity;

import com.nectech.client.MapleStoryClient;
import com.nectech.constant.Constant;
import com.nectech.util.ImageUtil;

import java.awt.*;

/**
 * @Author: 浅小北
 * @ClassName: Item
 * @Description: 道具类
 * @Date: 2021/1/29 12:44
 * @Since: version-1.0
 */
public class Prop extends AbstractMapleStoryObject{
    public MapleStoryClient msc;
    public int type;
    public Image img;
    public boolean jump;
    public int quantity = 1;
    public Prop(){}
    public Prop(MapleStoryClient msc,int x,int y,int type) {
        this.msc = msc;
        this.x = x;
        this.y = y;
        this.type = type;
        this.jump = true;
        this.live = true;
        switch (type) {
            case 0:
                this.img = ImageUtil.getImage("hp_50");
                break;
            case 1:
                this.img = ImageUtil.getImage("hp_100");
                break;
            case 2:
                this.img = ImageUtil.getImage("hp_300");
                break;
            case 3:
                this.img = ImageUtil.getImage("mp_100");
                break;
            default:
                break;
        }
        this.width = 30;
        this.height = 30;
    }
     /**
      * @Author: 浅小北
      * @Description: 道具重写draw方法
      * @Date: 18:30 2021/1/29
      * @Param:
      * @return:
      */
    @Override
    public void draw(Graphics g) {
        if (!this.live) {
            msc.propList.remove(this);
        }
        g.drawImage(img,x,y,null);
        move();
    }

     /**
      * @Author: 浅小北
      * @Description: 重写move方法，让道具一出来挑一下
      * @Date: 18:28 2021/1/29
      * @Param:
      * @return:
      */
    @Override
    public void move() {
        if (jump) {
            jump();
        }
    }

     /**
      * @Author: 浅小北
      * @Description: 道具跳跃的方法
      * @Date: 18:29 2021/1/29
      * @Param:
      * @return:
      */
    private double v0 = Constant.PROP_JUMP_SPEED;
    private double g = 9.8;
    private double vt;
    private double delta_height;
    private double t = 0.5;


    private void jump() {
        vt = v0 - g * t;
        delta_height = v0 * t;
        v0 = vt;
        y -= delta_height;
        if (y >= 740) {
            jump = false;
            v0 = Constant.PROP_JUMP_SPEED;
            vt = 0.0;
            y = 740;
        }
    }
}
